from django.shortcuts import render
from contactApp.models import recruit,offer
from django import forms
from django.core.paginator import Paginator
from django.shortcuts import redirect

class addBookModelForm(forms.ModelForm):
    class Meta:
        model = recruit
        fields = ['id','title','address','salary','intro','email','create_time']
        labels = {'id':'编号','title':'标题','address':'公司地址','salary':'薪水','intro':'要求','email':'邮箱','create_time':'日期'}
class modBookModelForm(addBookModelForm):
    isbn = forms.CharField(label='编号',widget=forms.TextInput(attrs={'readonly':'readonly'}))

def zpgg(request,pageNo):
    books = recruit.objects.all()
    pages = Paginator(books,10)
    page = pages.get_page(pageNo)
    d = {'page':page}
    t = 'zpgg.html'
    return render(request,t,d)

def modBook(request,id):
    bk = recruit.objects.get(id=id)
    if request.method == 'POST':
        mfrm = modBookModelForm(request.POST,instance=bk)
        if mfrm.is_valid():
            mfrm.save()
            msg = '数据修改成功！'
        else:
            msg = '数据校验未通过！'
    else:
        mfrm = modBookModelForm(instance=bk)
        msg = '请修改书本数据！'
    t = 'zpgg.html'
    d = {'title':'修改书本信息','url':'/moddata/','id':id,'form':mfrm,'msg':msg}
    return render(request,t,d)